// syscall number from https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
// AT&T syntax

// mov src, dest

#include <stdio.h>
#include <time.h>
int main()
{
    long int tid;
    clockid_t cpu_clock;
    clock_getcpuclockid(0,&cpu_clock);

    struct timespec start,end;
    clock_gettime(cpu_clock,&start);
    // x86-64 ia64 version
    asm (
        "movq $39,%%rax \n\t"
        "syscall \n\t"
        "movq %%rax,%0"
        : "=rm" (tid)
    );
    // i386 version
    // asm (
    //     "movl $39,%%eax \n\t"
    //     "int $0x80 \n\t "
    //     "movl %%eax,%0"
    //     : "=r" (pid)
    // );
    clock_gettime(cpu_clock,&end);
    printf("%ld used %ld ns + %lds \n",tid,end.tv_nsec-start.tv_nsec
        ,(long)end.tv_sec - (long)start.tv_sec);    
}